import 'package:testlzhu/generated/json/base/json_convert_content.dart';

/**
 * 基类数据，返回的参数为：{"code":0, "message":"", "data":{}}
 */
class BaseEntity<T> {
  //code = 1, 代表success
  static int STATUS_OK = 200;

  int code;
  String msg;
  T? data;

  BaseEntity({this.code = 500, this.msg = "", this.data});

  factory BaseEntity.fromJson(json) {
    var data = BaseEntity<T>();
    final int? code = jsonConvert.convert<int>(json['code']);
    if (code != null) {
      data.code = code;
    }
    final String? msg = jsonConvert.convert<String>(json['msg']);
    if (msg != null) {
      data.msg = msg;
    }
    T tdata = jsonConvert.convert<T>(json['data']) as T;

    data.data = tdata;
    return data;
  }


  factory BaseEntity.fromJson2(json) {
    var data = BaseEntity<T>();
    final int? code = jsonConvert.convert<int>(json['code']);
    if (code != null) {
      data.code = code;
    }
    final String? msg = jsonConvert.convert<String>(json['msg']);
    if (msg != null) {
      data.msg = msg;
    }
    T tdata = jsonConvert.convert<T>(json['data']) as T;

    data.data = tdata;
    return data;
  }
}
